package com.sinai.mshab.validation.gwt;

import com.google.gwt.user.client.ui.TextBoxBase;
import com.sinai.mshab.data.core.DataManager;
import com.sinai.mshab.data.gwt.TextBoxBaseDataManager;
import com.sinai.mshab.format.validation.AbstractValidatorImpl;
import com.sinai.mshab.format.validation.Validator;

/**
 * This concrete {@link Validator} checks whether a {@link TextBoxBase} is empty
 * or not.
 * 
 * @author Arthur Kalmenson
 */
public class NotEmptyValidator extends AbstractValidatorImpl<TextBoxBase> {

	private DataManager<TextBoxBase, String> dataManager;
	
	private TextBoxBase widget;

	public NotEmptyValidator(TextBoxBase widget) {

		dataManager =
				new TextBoxBaseDataManager();
		setWidget(widget);
	}

	public void setWidget(TextBoxBase widget) {
		
		this.widget = widget;
	}
	
	public TextBoxBase getWidget() {
		return widget;
	}

	/**
	 * Returns true if {@code widget} is not empty (whitespace counts as empty)
	 * and false otherwise.
	 * 
	 * @param widget
	 *            the {@link TextBoxBase} to validate.
	 * @return true if {@code widget} is valid and false otherwise.
	 */
	public boolean validate() {
		return dataManager.getData(widget).trim().length() > 0;
	}

	public void notifyObservers() {
		// TODO Auto-generated method stub
		
	}
}
